package com.dtagri.fjwlw.ui;

import android.content.Intent;
import android.net.Uri;
import android.support.v4.app.Fragment;
import android.view.View;
import android.webkit.DownloadListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import butterknife.InjectView;

import com.dtagri.fjwlw.R;
import com.dtagri.fjwlw.base.BaseActivity;
import com.dtagri.fjwlw.base.BaseSimpleActivity;
import com.dtagri.fjwlw.fragment.RealTimeDataFragment;
import com.dtagri.fjwlw.widget.ProgressWebView;

/**
 * WebView
 * @author CL.
 *  2015-12-05
 */
public class WebViewActivity extends BaseActivity {
	@InjectView(R.id.webView)
	ProgressWebView  webview;
	
	@Override
	public void onClick(View arg0) {
	}

	@Override
	public void initView() {
		String url = getIntent().getStringExtra("url");
		String title =  getIntent().getStringExtra("title");
		setActionBarTitle(title);
		
		webview.getSettings().setJavaScriptEnabled(true);
	    webview.setDownloadListener(new DownloadListener() {
            @Override
            public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
                if (url != null && url.startsWith("http://"))
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            }
	     });
	    webview.loadUrl(url);
		
		
		/*
		 * 标准
		 * webview.loadUrl("http://baidu.com");
		 //覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为，使网页用WebView打开
		webview.setWebViewClient(new WebViewClient(){
           @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub
               //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
             view.loadUrl(url);
            return true;
        }
       });*/
	}

	@Override
	public void initData() {
		// TODO Auto-generated method stub
	}
	
	@Override
	protected int getLayoutId() {
		return R.layout.layout_webview;
	}


	
}
